package com.dona.imsidetector.utils;

import android.util.Log;

import org.xutils.DbManager;
import org.xutils.ex.DbException;
import org.xutils.x;

/**
 * 数据库帮助类
 */
public class DatabaseOpenHelper {
 
    private final String TAG = DatabaseOpenHelper.class.getSimpleName();
    private DbManager.DaoConfig daoConfig;
    private static DbManager dbManager;
    private final String DB_NAME = "imsidetector.db";
    private final int DB_VERSION = 1;
 
    private DatabaseOpenHelper() {

        daoConfig = new DbManager.DaoConfig()
                .setDbName(DB_NAME)
                .setDbVersion(DB_VERSION)
                .setDbOpenListener(db -> db.getDatabase().enableWriteAheadLogging())
                .setDbUpgradeListener((db, oldVersion, newVersion) -> {

                }).setTableCreateListener((db, table) -> {

                });
        dbManager = x.getDb(daoConfig);
    }
 
    public static DbManager getInstance() {
        if (dbManager == null) {
            Log.e("TAG", "getInstance: new Instance" );
            DatabaseOpenHelper databaseOpenHelper = new DatabaseOpenHelper();
        }
        Log.e("dbversion", "getInstance: "+dbManager.getDatabase().getVersion());
        return dbManager;
    }
    
}